package vo

import (
	"encoding/xml"
	"io"
)

// RssMeta 源信息
type RssMeta struct {
	Name   string
	RssUrl string
}

// RssBody rss内容body
type RssBody struct {
	Channel RssChannel `xml:"channel"`
}

type RssChannel struct {
	Title       string `xml:"title"`
	Description string `xml:"description"`
	Link        string `xml:"link"`
	PubDate     string `xml:"pubDate"`
	Language    string `xml:"language"`
	Copyright   string `xml:"copyright"`
	Generator   string `xml:"generator"`
	Image       struct {
		Title string `xml:"title"`
		Url   string `xml:"url"`
		Link  string `xml:"link"`
	} `xml:"image"`
	Items []*RssItems `xml:"item"`
}

type RssItems struct {
	Title       string `json:"title" xml:"title"`             //新闻标题
	Author      string `json:"author" xml:"author"`           //作者
	Link        string `json:"link" xml:"link"`               //连接
	PubDate     string `json:"pubDate" xml:"pubDate"`         //发布日期/时间
	Description string `json:"description" xml:"description"` //描述信息
}

func (rss *RssBody) Parse(r io.Reader) error {
	decoder := xml.NewDecoder(r)
	err := decoder.Decode(rss)
	if err != nil {
		return err
	}

	return nil
}
